home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / MacPerl 5.1.3 / Mac_Perl_513_src / perl5.002 / perl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-02  |  40.2 KB  |  1,626 lines  |  [TEXT/MPS ]

  1. /*    perl.h
  2.  *
  3.  *    Copyright (c) 1987-1994, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9. #ifndef H_PERL
  10. #define H_PERL 1
  11. #define OVERLOAD
  12.  
  13. /*
  14.  * STMT_START { statements; } STMT_END;
  15.  * can be used as a single statement, as in
  16.  * if (x) STMT_START { ... } STMT_END; else ...
  17.  *
  18.  * Trying to select a version that gives no warnings...
  19.  */
  20. #if !(defined(STMT_START) && defined(STMT_END))
  21. # if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  22. #   define STMT_START    (void)(    /* gcc supports ``({ STATEMENTS; })'' */
  23. #   define STMT_END    )
  24. # else
  25.    /* Now which other defined()s do we need here ??? */
  26. #  if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
  27. #   define STMT_START    if (1)
  28. #   define STMT_END    else (void)0
  29. #  else
  30. #   define STMT_START    do
  31. #   define STMT_END    while (0)
  32. #  endif
  33. # endif
  34. #endif
  35.  
  36. #include "embed.h"
  37.  
  38. #define VOIDUSED 1
  39. #include "config.h"
  40.  
  41. #ifndef BYTEORDER
  42. #   define BYTEORDER 0x1234
  43. #endif
  44.  
  45. /* Overall memory policy? */
  46. #ifndef CONSERVATIVE
  47. #   define LIBERAL 1
  48. #endif
  49.  
  50. /*
  51.  * The following contortions are brought to you on behalf of all the
  52.  * standards, semi-standards, de facto standards, not-so-de-facto standards
  53.  * of the world, as well as all the other botches anyone ever thought of.
  54.  * The basic theory is that if we work hard enough here, the rest of the
  55.  * code can be a lot prettier.  Well, so much for theory.  Sorry, Henry...
  56.  */
  57.  
  58. /* define this once if either system, instead of cluttering up the src */
  59. #if defined(MSDOS) || defined(atarist)
  60. #define DOSISH 1
  61. #endif
  62.  
  63. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  64. # define STANDARD_C 1
  65. #endif
  66.  
  67. #if defined(HASVOLATILE) || defined(STANDARD_C)
  68. #   ifdef __cplusplus
  69. #    define VOL        // to temporarily suppress warnings
  70. #   else
  71. #    define VOL volatile
  72. #   endif
  73. #else
  74. #   define VOL
  75. #endif
  76.  
  77. #define TAINT_IF(c)    (tainted |= (c))
  78. #define TAINT_NOT    (tainted = 0)
  79. #define TAINT_PROPER(s)    if (tainting) taint_proper(no_security, s)
  80. #define TAINT_ENV()    if (tainting) taint_env()
  81.  
  82. #ifdef USE_BSDPGRP
  83. #   ifdef HAS_GETPGRP
  84. #       define BSD_GETPGRP(pid) getpgrp((pid))
  85. #   endif
  86. #   ifdef HAS_SETPGRP
  87. #       define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
  88. #   endif
  89. #else
  90. #   ifdef HAS_GETPGRP2
  91. #       define BSD_GETPGRP(pid) getpgrp2((pid))
  92. #       ifndef HAS_GETPGRP
  93. #            define HAS_GETPGRP
  94. #        endif
  95. #   endif
  96. #   ifdef HAS_SETPGRP2
  97. #       define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
  98. #       ifndef HAS_SETPGRP
  99. #            define HAS_SETPGRP
  100. #        endif
  101. #   endif
  102. #endif
  103.  
  104. #include <stdio.h>
  105. #ifdef USE_NEXT_CTYPE
  106. #include <appkit/NXCType.h>
  107. #else
  108. #include <ctype.h>
  109. #endif
  110.  
  111. #ifdef I_LOCALE
  112. #include <locale.h>
  113. #endif
  114.  
  115. #ifdef METHOD     /* Defined by OSF/1 v3.0 by ctype.h */
  116. #undef METHOD
  117. #endif
  118.  
  119. #include <setjmp.h>
  120.  
  121. #ifdef I_SYS_PARAM
  122. #   ifdef PARAM_NEEDS_TYPES
  123. #    include <sys/types.h>
  124. #   endif
  125. #   include <sys/param.h>
  126. #endif
  127.  
  128.  
  129. /* Use all the "standard" definitions? */
  130. #if defined(STANDARD_C) && defined(I_STDLIB)
  131. #   include <stdlib.h>
  132. #endif /* STANDARD_C */
  133.  
  134. /* Maybe this comes after <stdlib.h> so we don't try to change 
  135.    the standard library prototypes?.  We'll use our own in 
  136.    proto.h instead.  I guess.  The patch had no explanation.
  137. */
  138. #ifdef MYMALLOC
  139. #   ifdef HIDEMYMALLOC
  140. #    define malloc Mymalloc
  141. #    define realloc Myremalloc
  142. #    define free Myfree
  143. #   endif
  144. #   define safemalloc malloc
  145. #   define saferealloc realloc
  146. #   define safefree free
  147. #endif
  148.  
  149. #define MEM_SIZE Size_t
  150.  
  151. #if defined(I_STRING) || defined(__cplusplus)
  152. #   include <string.h>
  153. #else
  154. #   include <strings.h>
  155. #endif
  156.  
  157. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  158. #define strchr index
  159. #define strrchr rindex
  160. #endif
  161.  
  162. #if defined(mips) && defined(ultrix) && !defined(__STDC__)
  163. #   undef HAS_MEMCMP
  164. #endif
  165.  
  166. #ifdef I_MEMORY
  167. #  include <memory.h>
  168. #endif
  169.  
  170. #ifdef HAS_MEMCPY
  171. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  172. #    ifndef memcpy
  173.         extern char * memcpy _((char*, char*, int));
  174. #    endif
  175. #  endif
  176. #else
  177. #   ifndef memcpy
  178. #    ifdef HAS_BCOPY
  179. #        define memcpy(d,s,l) bcopy(s,d,l)
  180. #    else
  181. #        define memcpy(d,s,l) my_bcopy(s,d,l)
  182. #    endif
  183. #   endif
  184. #endif /* HAS_MEMCPY */
  185.  
  186. #ifdef HAS_MEMSET
  187. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  188. #    ifndef memset
  189.     extern char *memset _((char*, int, int));
  190. #    endif
  191. #  endif
  192. #  define memzero(d,l) memset(d,0,l)
  193. #else
  194. #   ifndef memzero
  195. #    ifdef HAS_BZERO
  196. #        define memzero(d,l) bzero(d,l)
  197. #    else
  198. #        define memzero(d,l) my_bzero(d,l)
  199. #    endif
  200. #   endif
  201. #endif /* HAS_MEMSET */
  202.  
  203. #ifdef HAS_MEMCMP
  204. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  205. #    ifndef memcmp
  206.     extern int memcmp _((char*, char*, int));
  207. #    endif
  208. #  endif
  209. #else
  210. #   ifndef memcmp
  211. #    define memcmp     my_memcmp
  212. #   endif
  213. #endif /* HAS_MEMCMP */
  214.  
  215. /* XXX we prefer bcmp slightly for comparisons that don't care about ordering */
  216. #ifndef HAS_BCMP
  217. #   ifndef bcmp
  218. #    define bcmp(s1,s2,l) memcmp(s1,s2,l)
  219. #   endif
  220. #endif /* HAS_BCMP */
  221.  
  222. #if !defined(HAS_MEMMOVE) && !defined(memmove)
  223. #   if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
  224. #    define memmove(d,s,l) bcopy(s,d,l)
  225. #   else
  226. #    if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
  227. #        define memmove(d,s,l) memcpy(d,s,l)
  228. #    else
  229. #        define memmove(d,s,l) my_bcopy(s,d,l)
  230. #    endif
  231. #   endif
  232. #endif
  233.  
  234. #ifndef _TYPES_        /* If types.h defines this it's easy. */
  235. #   ifndef major        /* Does everyone's types.h define this? */
  236. #    include <sys/types.h>
  237. #   endif
  238. #endif
  239.  
  240. #ifdef I_NETINET_IN
  241. #   include <netinet/in.h>
  242. #endif
  243.  
  244. #ifdef I_SYS_STAT
  245. #include <sys/stat.h>
  246. #endif
  247.  
  248. /* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
  249.    like UTekV) are broken, sometimes giving false positives.  Undefine
  250.    them here and let the code below set them to proper values.
  251.  
  252.    The ghs macro stands for GreenHills Software C-1.8.5 which
  253.    is the C compiler for sysV88 and the various derivatives.
  254.    This header file bug is corrected in gcc-2.5.8 and later versions.
  255.    --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94.  */
  256.  
  257. #if defined(uts) || (defined(m88k) && defined(ghs))
  258. #   undef S_ISDIR
  259. #   undef S_ISCHR
  260. #   undef S_ISBLK
  261. #   undef S_ISREG
  262. #   undef S_ISFIFO
  263. #   undef S_ISLNK
  264. #endif
  265.  
  266. #ifdef I_TIME
  267. #   include <time.h>
  268. #endif
  269.  
  270. #ifdef I_SYS_TIME
  271. #   ifdef I_SYS_TIME_KERNEL
  272. #    define KERNEL
  273. #   endif
  274. #   include <sys/time.h>
  275. #   ifdef I_SYS_TIME_KERNEL
  276. #    undef KERNEL
  277. #   endif
  278. #endif
  279.  
  280. #ifndef MSDOS
  281. #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  282. #    include <sys/times.h>
  283. #  endif
  284. #endif
  285.  
  286. #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
  287. #   undef HAS_STRERROR
  288. #endif
  289.  
  290. #ifndef HAS_MKFIFO
  291. #  ifndef mkfifo
  292. #    define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
  293. #  endif
  294. #endif /* !HAS_MKFIFO */
  295.  
  296. #include <errno.h>
  297. #ifdef HAS_SOCKET
  298. #   ifdef I_NET_ERRNO
  299. #     include <net/errno.h>
  300. #   endif
  301. #endif
  302. #ifndef VMS
  303. #   define FIXSTATUS(sts)  (U_L((sts) & 0xffff))
  304. #   define SHIFTSTATUS(sts) ((sts) >> 8)
  305. #   define SETERRNO(errcode,vmserrcode) errno = (errcode)
  306. #else
  307. #   define FIXSTATUS(sts)  (U_L(sts))
  308. #   define SHIFTSTATUS(sts) (sts)
  309. #   define SETERRNO(errcode,vmserrcode) STMT_START {set_errno(errcode); set_vaxc_errno(vmserrcode);} STMT_END
  310. #endif
  311.  
  312. #ifndef MSDOS
  313. #   ifndef errno
  314.     extern int errno;     /* ANSI allows errno to be an lvalue expr */
  315. #   endif
  316. #endif
  317.  
  318. #ifdef HAS_STRERROR
  319. #       ifdef VMS
  320.     char *strerror _((int,...));
  321. #       else
  322.     char *strerror _((int));
  323. #       endif
  324. #       ifndef Strerror
  325. #           define Strerror strerror
  326. #       endif
  327. #else
  328. #    ifdef HAS_SYS_ERRLIST
  329.     extern int sys_nerr;
  330.     extern char *sys_errlist[];
  331. #       ifndef Strerror
  332. #           define Strerror(e) \
  333.         ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
  334. #       endif
  335. #   endif
  336. #endif
  337.  
  338. #ifdef I_SYS_IOCTL
  339. #   ifndef _IOCTL_
  340. #    include <sys/ioctl.h>
  341. #   endif
  342. #endif
  343.  
  344. #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
  345. #   ifdef HAS_SOCKETPAIR
  346. #    undef HAS_SOCKETPAIR
  347. #   endif
  348. #   ifdef I_NDBM
  349. #    undef I_NDBM
  350. #   endif
  351. #endif
  352.  
  353. #if INTSIZE == 2
  354. #   define htoni htons
  355. #   define ntohi ntohs
  356. #else
  357. #   define htoni htonl
  358. #   define ntohi ntohl
  359. #endif
  360.  
  361. /* Configure already sets Direntry_t */
  362. #if defined(I_DIRENT)
  363. #   include <dirent.h>
  364. #   if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
  365. #    include <sys/dir.h>
  366. #   endif
  367. #else
  368. #   ifdef I_SYS_NDIR
  369. #    include <sys/ndir.h>
  370. #   else
  371. #    ifdef I_SYS_DIR
  372. #        ifdef hp9000s500
  373. #        include <ndir.h>    /* may be wrong in the future */
  374. #        else
  375. #        include <sys/dir.h>
  376. #        endif
  377. #    endif
  378. #   endif
  379. #endif
  380.  
  381. #ifdef FPUTS_BOTCH
  382. /* work around botch in SunOS 4.0.1 and 4.0.2 */
  383. #   ifndef fputs
  384. #    define fputs(sv,fp) fprintf(fp,"%s",sv)
  385. #   endif
  386. #endif
  387.  
  388. /*
  389.  * The following gobbledygook brought to you on behalf of __STDC__.
  390.  * (I could just use #ifndef __STDC__, but this is more bulletproof
  391.  * in the face of half-implementations.)
  392.  */
  393.  
  394. #ifndef S_IFMT
  395. #   ifdef _S_IFMT
  396. #    define S_IFMT _S_IFMT
  397. #   else
  398. #    define S_IFMT 0170000
  399. #   endif
  400. #endif
  401.  
  402. #ifndef S_ISDIR
  403. #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
  404. #endif
  405.  
  406. #ifndef S_ISCHR
  407. #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
  408. #endif
  409.  
  410. #ifndef S_ISBLK
  411. #   ifdef S_IFBLK
  412. #    define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
  413. #   else
  414. #    define S_ISBLK(m) (0)
  415. #   endif
  416. #endif
  417.  
  418. #ifndef S_ISREG
  419. #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
  420. #endif
  421.  
  422. #ifndef S_ISFIFO
  423. #   ifdef S_IFIFO
  424. #    define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
  425. #   else
  426. #    define S_ISFIFO(m) (0)
  427. #   endif
  428. #endif
  429.  
  430. #ifndef S_ISLNK
  431. #   ifdef _S_ISLNK
  432. #    define S_ISLNK(m) _S_ISLNK(m)
  433. #   else
  434. #    ifdef _S_IFLNK
  435. #        define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
  436. #    else
  437. #        ifdef S_IFLNK
  438. #        define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
  439. #        else
  440. #        define S_ISLNK(m) (0)
  441. #        endif
  442. #    endif
  443. #   endif
  444. #endif
  445.  
  446. #ifndef S_ISSOCK
  447. #   ifdef _S_ISSOCK
  448. #    define S_ISSOCK(m) _S_ISSOCK(m)
  449. #   else
  450. #    ifdef _S_IFSOCK
  451. #        define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
  452. #    else
  453. #        ifdef S_IFSOCK
  454. #        define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
  455. #        else
  456. #        define S_ISSOCK(m) (0)
  457. #        endif
  458. #    endif
  459. #   endif
  460. #endif
  461.  
  462. #ifndef S_IRUSR
  463. #   ifdef S_IREAD
  464. #    define S_IRUSR S_IREAD
  465. #    define S_IWUSR S_IWRITE
  466. #    define S_IXUSR S_IEXEC
  467. #   else
  468. #    define S_IRUSR 0400
  469. #    define S_IWUSR 0200
  470. #    define S_IXUSR 0100
  471. #   endif
  472. #   define S_IRGRP (S_IRUSR>>3)
  473. #   define S_IWGRP (S_IWUSR>>3)
  474. #   define S_IXGRP (S_IXUSR>>3)
  475. #   define S_IROTH (S_IRUSR>>6)
  476. #   define S_IWOTH (S_IWUSR>>6)
  477. #   define S_IXOTH (S_IXUSR>>6)
  478. #endif
  479.  
  480. #ifndef S_ISUID
  481. #   define S_ISUID 04000
  482. #endif
  483.  
  484. #ifndef S_ISGID
  485. #   define S_ISGID 02000
  486. #endif
  487.  
  488. #ifdef ff_next
  489. #   undef ff_next
  490. #endif
  491.  
  492. #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
  493. #   define SLOPPYDIVIDE
  494. #endif
  495.  
  496. #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
  497. #   define HAS_QUAD
  498. #endif
  499.  
  500. #ifdef UV
  501. #undef UV
  502. #endif
  503.  
  504. #ifdef HAS_QUAD
  505. #   ifdef cray
  506. #    define Quad_t int
  507. #   else
  508. #    if defined(convex) || defined (uts)
  509. #        define Quad_t long long
  510. #    else
  511. #        define Quad_t long
  512. #    endif
  513. #   endif
  514.     typedef Quad_t IV;
  515.     typedef unsigned Quad_t UV;
  516. #else
  517.     typedef long IV;
  518.     typedef unsigned long UV;
  519. #endif
  520.  
  521. typedef MEM_SIZE STRLEN;
  522.  
  523. typedef struct op OP;
  524. typedef struct cop COP;
  525. typedef struct unop UNOP;
  526. typedef struct binop BINOP;
  527. typedef struct listop LISTOP;
  528. typedef struct logop LOGOP;
  529. typedef struct condop CONDOP;
  530. typedef struct pmop PMOP;
  531. typedef struct svop SVOP;
  532. typedef struct gvop GVOP;
  533. typedef struct pvop PVOP;
  534. typedef struct loop LOOP;
  535.  
  536. typedef struct Outrec Outrec;
  537. typedef struct interpreter PerlInterpreter;
  538. typedef struct ff FF;
  539. typedef struct sv SV;
  540. typedef struct av AV;
  541. typedef struct hv HV;
  542. typedef struct cv CV;
  543. typedef struct regexp REGEXP;
  544. typedef struct gp GP;
  545. typedef struct sv GV;
  546. typedef struct io IO;
  547. typedef struct context CONTEXT;
  548. typedef struct block BLOCK;
  549.  
  550. typedef struct magic MAGIC;
  551. typedef struct xrv XRV;
  552. typedef struct xpv XPV;
  553. typedef struct xpviv XPVIV;
  554. typedef struct xpvnv XPVNV;
  555. typedef struct xpvmg XPVMG;
  556. typedef struct xpvlv XPVLV;
  557. typedef struct xpvav XPVAV;
  558. typedef struct xpvhv XPVHV;
  559. typedef struct xpvgv XPVGV;
  560. typedef struct xpvcv XPVCV;
  561. typedef struct xpvbm XPVBM;
  562. typedef struct xpvfm XPVFM;
  563. typedef struct xpvio XPVIO;
  564. typedef struct mgvtbl MGVTBL;
  565. typedef union any ANY;
  566.  
  567. #include "handy.h"
  568.  
  569. typedef I32 (*filter_t) _((int, SV *, int));
  570. #define FILTER_READ(idx, sv, len)  filter_read(idx, sv, len)
  571. #define FILTER_DATA(idx)       (AvARRAY(rsfp_filters)[idx])
  572. #define FILTER_ISREADER(idx)       (idx >= AvFILL(rsfp_filters))
  573.  
  574. #ifdef macintosh
  575. #   include "macish.h"
  576. #else
  577. # ifdef DOSISH
  578. #  if defined(OS2)
  579. #    include "os2ish.h"
  580. #  else
  581. #    include "dosish.h"
  582. #  endif
  583. # else
  584. #  if defined(VMS)
  585. #    include "vmsish.h"
  586. #  else
  587. #    include "unixish.h"
  588. #  endif
  589. # endif
  590. #endif
  591.  
  592. #ifndef HAS_PAUSE
  593. #define pause() sleep((32767<<16)+32767)
  594. #endif
  595.  
  596. #ifndef IOCPARM_LEN
  597. #   ifdef IOCPARM_MASK
  598.     /* on BSDish systes we're safe */
  599. #    define IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)
  600. #   else
  601.     /* otherwise guess at what's safe */
  602. #    define IOCPARM_LEN(x)    256
  603. #   endif
  604. #endif
  605.  
  606. union any {
  607.     void*    any_ptr;
  608.     I32        any_i32;
  609.     IV        any_iv;
  610.     long    any_long;
  611.     void    (*any_dptr) _((void*));
  612. };
  613.  
  614. #include "regexp.h"
  615. #include "sv.h"
  616. #include "util.h"
  617. #include "form.h"
  618. #include "gv.h"
  619. #include "cv.h"
  620. #include "opcode.h"
  621. #include "op.h"
  622. #include "cop.h"
  623. #include "av.h"
  624. #include "hv.h"
  625. #include "mg.h"
  626. #include "scope.h"
  627.  
  628. /* work around some libPW problems */
  629. #ifdef DOINIT
  630. EXT char Error[1];
  631. #endif
  632.  
  633. #if defined(iAPX286) || defined(M_I286) || defined(I80286)
  634. #   define I286
  635. #endif
  636.  
  637. #if defined(htonl) && !defined(HAS_HTONL)
  638. #define HAS_HTONL
  639. #endif
  640. #if defined(htons) && !defined(HAS_HTONS)
  641. #define HAS_HTONS
  642. #endif
  643. #if defined(ntohl) && !defined(HAS_NTOHL)
  644. #define HAS_NTOHL
  645. #endif
  646. #if defined(ntohs) && !defined(HAS_NTOHS)
  647. #define HAS_NTOHS
  648. #endif
  649. #ifndef HAS_HTONL
  650. #if (BYTEORDER & 0xffff) != 0x4321
  651. #define HAS_HTONS
  652. #define HAS_HTONL
  653. #define HAS_NTOHS
  654. #define HAS_NTOHL
  655. #define MYSWAP
  656. #define htons my_swap
  657. #define htonl my_htonl
  658. #define ntohs my_swap
  659. #define ntohl my_ntohl
  660. #endif
  661. #else
  662. #if (BYTEORDER & 0xffff) == 0x4321
  663. #undef HAS_HTONS
  664. #undef HAS_HTONL
  665. #undef HAS_NTOHS
  666. #undef HAS_NTOHL
  667. #endif
  668. #endif
  669.  
  670. /*
  671.  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
  672.  * -DWS
  673.  */
  674. #if BYTEORDER != 0x1234
  675. # define HAS_VTOHL
  676. # define HAS_VTOHS
  677. # define HAS_HTOVL
  678. # define HAS_HTOVS
  679. # if BYTEORDER == 0x4321
  680. #  define vtohl(x)    ((((x)&0xFF)<<24)    \
  681.             +(((x)>>24)&0xFF)    \
  682.             +(((x)&0x0000FF00)<<8)    \
  683.             +(((x)&0x00FF0000)>>8)    )
  684. #  define vtohs(x)    ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
  685. #  define htovl(x)    vtohl(x)
  686. #  define htovs(x)    vtohs(x)
  687. # endif
  688.     /* otherwise default to functions in util.c */
  689. #endif
  690.  
  691. #ifdef CASTNEGFLOAT
  692. #define U_S(what) ((U16)(what))
  693. #define U_I(what) ((unsigned int)(what))
  694. #define U_L(what) ((U32)(what))
  695. #else
  696. U32 cast_ulong _((double));
  697. #define U_S(what) ((U16)cast_ulong((double)(what)))
  698. #define U_I(what) ((unsigned int)cast_ulong((double)(what)))
  699. #define U_L(what) (cast_ulong((double)(what)))
  700. #endif
  701.  
  702. #ifdef CASTI32
  703. #define I_32(what) ((I32)(what))
  704. #define I_V(what) ((IV)(what))
  705. #define U_V(what) ((UV)(what))
  706. #else
  707. I32 cast_i32 _((double));
  708. #define I_32(what) (cast_i32((double)(what)))
  709. IV cast_iv _((double));
  710. #define I_V(what) (cast_iv((double)(what)))
  711. UV cast_uv _((double));
  712. #define U_V(what) (cast_uv((double)(what)))
  713. #endif
  714.  
  715. struct Outrec {
  716.     I32        o_lines;
  717.     char    *o_str;
  718.     U32        o_len;
  719. };
  720.  
  721. #ifndef MAXSYSFD
  722. #   define MAXSYSFD 2
  723. #endif
  724.  
  725. #ifndef TMPPATH
  726. #  define TMPPATH "/tmp/perl-eXXXXXX"
  727. #endif
  728.  
  729. #ifndef __cplusplus
  730. Uid_t getuid _((void));
  731. Uid_t geteuid _((void));
  732. Gid_t getgid _((void));
  733. Gid_t getegid _((void));
  734. #endif
  735.  
  736. #ifdef DEBUGGING
  737. #ifndef Perl_debug_log
  738. #define Perl_debug_log    stderr
  739. #endif
  740. #define YYDEBUG 1
  741. #define DEB(a)                 a
  742. #define DEBUG(a)   if (debug)        a
  743. #define DEBUG_p(a) if (debug & 1)    a
  744. #define DEBUG_s(a) if (debug & 2)    a
  745. #define DEBUG_l(a) if (debug & 4)    a
  746. #define DEBUG_t(a) if (debug & 8)    a
  747. #define DEBUG_o(a) if (debug & 16)    a
  748. #define DEBUG_c(a) if (debug & 32)    a
  749. #define DEBUG_P(a) if (debug & 64)    a
  750. #define DEBUG_m(a) if (curinterp && debug & 128)    a
  751. #define DEBUG_f(a) if (debug & 256)    a
  752. #define DEBUG_r(a) if (debug & 512)    a
  753. #define DEBUG_x(a) if (debug & 1024)    a
  754. #define DEBUG_u(a) if (debug & 2048)    a
  755. #define DEBUG_L(a) if (debug & 4096)    a
  756. #define DEBUG_H(a) if (debug & 8192)    a
  757. #define DEBUG_X(a) if (debug & 16384)    a
  758. #define DEBUG_D(a) if (debug & 32768)    a
  759. #else
  760. #define DEB(a)
  761. #define DEBUG(a)
  762. #define DEBUG_p(a)
  763. #define DEBUG_s(a)
  764. #define DEBUG_l(a)
  765. #define DEBUG_t(a)
  766. #define DEBUG_o(a)
  767. #define DEBUG_c(a)
  768. #define DEBUG_P(a)
  769. #define DEBUG_m(a)
  770. #define DEBUG_f(a)
  771. #define DEBUG_r(a)
  772. #define DEBUG_x(a)
  773. #define DEBUG_u(a)
  774. #define DEBUG_L(a)
  775. #define DEBUG_H(a)
  776. #define DEBUG_X(a)
  777. #define DEBUG_D(a)
  778. #endif
  779. #define YYMAXDEPTH 300
  780.  
  781. #define assert(what)    DEB( {                        \
  782.     if (!(what)) {                            \
  783.         croak("Assertion failed: file \"%s\", line %d",        \
  784.         __FILE__, __LINE__);                    \
  785.         exit(1);                            \
  786.     }})
  787.  
  788. struct ufuncs {
  789.     I32 (*uf_val)_((IV, SV*));
  790.     I32 (*uf_set)_((IV, SV*));
  791.     IV uf_index;
  792. };
  793.  
  794. /* Fix these up for __STDC__ */
  795. #ifndef __cplusplus
  796. char *mktemp _((char*));
  797. double atof _((const char*));
  798. #endif
  799.  
  800. #ifndef STANDARD_C
  801. /* All of these are in stdlib.h or time.h for ANSI C */
  802. Time_t time();
  803. struct tm *gmtime(), *localtime();
  804. char *strchr(), *strrchr();
  805. char *strcpy(), *strcat();
  806. #endif /* ! STANDARD_C */
  807.  
  808.  
  809. #ifdef I_MATH
  810. #    include <math.h>
  811. #else
  812. #   ifdef __cplusplus
  813.     extern "C" {
  814. #   endif
  815.         double exp _((double));
  816.         double log _((double));
  817.         double sqrt _((double));
  818.         double modf _((double,double*));
  819.         double sin _((double));
  820.         double cos _((double));
  821.         double atan2 _((double,double));
  822.         double pow _((double,double));
  823. #   ifdef __cplusplus
  824.     };
  825. #   endif
  826. #endif
  827.  
  828. #ifndef __cplusplus
  829. char *crypt _((const char*, const char*));
  830. char *getenv _((const char*));
  831. Off_t lseek _((int,Off_t,int));
  832. char *getlogin _((void));
  833. #endif
  834.  
  835. #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
  836. #define UNLINK unlnk
  837. I32 unlnk _((char*));
  838. #else
  839. #define UNLINK unlink
  840. #endif
  841.  
  842. #ifndef HAS_SETREUID
  843. #  ifdef HAS_SETRESUID
  844. #    define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
  845. #    define HAS_SETREUID
  846. #  endif
  847. #endif
  848. #ifndef HAS_SETREGID
  849. #  ifdef HAS_SETRESGID
  850. #    define setregid(r,e) setresgid(r,e,(Gid_t)-1)
  851. #    define HAS_SETREGID
  852. #  endif
  853. #endif
  854.  
  855. #define SCAN_DEF 0
  856. #define SCAN_TR 1
  857. #define SCAN_REPL 2
  858.  
  859. #ifdef DEBUGGING
  860. # ifndef register
  861. #  define register
  862. # endif
  863. # ifdef MYMALLOC
  864. # define DEBUGGING_MSTATS
  865. # endif
  866. # define PAD_SV(po) pad_sv(po)
  867. #else
  868. # define PAD_SV(po) curpad[po]
  869. #endif
  870.  
  871. /****************/
  872. /* Truly global */
  873. /****************/
  874.  
  875. /* global state */
  876. EXT PerlInterpreter *    curinterp;    /* currently running interpreter */
  877. #ifndef VMS  /* VMS doesn't use environ array */
  878. extern char **    environ;    /* environment variables supplied via exec */
  879. #endif
  880. EXT int        uid;        /* current real user id */
  881. EXT int        euid;        /* current effective user id */
  882. EXT int        gid;        /* current real group id */
  883. EXT int        egid;        /* current effective group id */
  884. EXT bool    nomemok;    /* let malloc context handle nomem */
  885. EXT U32        an;        /* malloc sequence number */
  886. EXT U32        cop_seqmax;    /* statement sequence number */
  887. EXT U16        op_seqmax;    /* op sequence number */
  888. EXT U32        evalseq;    /* eval sequence number */
  889. EXT U32        sub_generation;    /* inc to force methods to be looked up again */
  890. EXT char **    origenviron;
  891. EXT U32        origalen;
  892. EXT U32 *    profiledata;
  893. EXT int        maxo INIT(MAXO);/* Number of ops */
  894. EXT char *    osname;        /* operating system */
  895.  
  896. EXT XPV*    xiv_arenaroot;    /* list of allocated xiv areas */
  897. EXT IV **    xiv_root;    /* free xiv list--shared by interpreters */
  898. EXT double *    xnv_root;    /* free xnv list--shared by interpreters */
  899. EXT XRV *    xrv_root;    /* free xrv list--shared by interpreters */
  900. EXT XPV *    xpv_root;    /* free xpv list--shared by interpreters */
  901. EXT HE *    he_root;    /* free he list--shared by interpreters */
  902. EXT char *    nice_chunk;    /* a nice chunk of memory to reuse */
  903. EXT U32        nice_chunk_size;/* how nice the chunk of memory is */
  904.  
  905. /* Stack for currently executing thread--context switch must handle this.     */
  906. EXT SV **    stack_base;    /* stack->array_ary */
  907. EXT SV **    stack_sp;    /* stack pointer now */
  908. EXT SV **    stack_max;    /* stack->array_ary + stack->array_max */
  909.  
  910. /* likewise for these */
  911.  
  912. EXT OP *    op;        /* current op--oughta be in a global register */
  913.  
  914. EXT I32 *    scopestack;    /* blocks we've entered */
  915. EXT I32        scopestack_ix;
  916. EXT I32        scopestack_max;
  917.  
  918. EXT ANY*    savestack;    /* to save non-local values on */
  919. EXT I32        savestack_ix;
  920. EXT I32        savestack_max;
  921.  
  922. EXT OP **    retstack;    /* returns we've pushed */
  923. EXT I32        retstack_ix;
  924. EXT I32        retstack_max;
  925.  
  926. EXT I32 *    markstack;    /* stackmarks we're remembering */
  927. EXT I32 *    markstack_ptr;    /* stackmarks we're remembering */
  928. EXT I32 *    markstack_max;    /* stackmarks we're remembering */
  929.  
  930. EXT SV **    curpad;
  931.  
  932. /* temp space */
  933. EXT SV *    Sv;
  934. EXT XPV *    Xpv;
  935. EXT char    buf[2048];    /* should be longer than PATH_MAX */
  936. EXT char    tokenbuf[256];
  937. EXT struct stat    statbuf;
  938. #ifdef HAS_TIMES
  939. EXT struct tms    timesbuf;
  940. #endif
  941. EXT STRLEN na;        /* for use in SvPV when length is Not Applicable */
  942.  
  943. /* for tmp use in stupid debuggers */
  944. EXT int *    di;
  945. EXT short *    ds;
  946. EXT char *    dc;
  947.  
  948. /* handy constants */
  949. EXT char *    Yes INIT("1");
  950. EXT char *    No INIT("");
  951. EXT char *    hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
  952. EXT char *    patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}");
  953. EXT char *    vert INIT("|");
  954.  
  955. EXT char    warn_uninit[]
  956.   INIT("Use of uninitialized value");
  957. EXT char    warn_nosemi[]
  958.   INIT("Semicolon seems to be missing");
  959. EXT char    warn_reserved[]
  960.   INIT("Unquoted string \"%s\" may clash with future reserved word");
  961. EXT char    warn_nl[]
  962.   INIT("Unsuccessful %s on filename containing newline");
  963. EXT char    no_wrongref[]
  964.   INIT("Can't use %s ref as %s ref");
  965. EXT char    no_symref[]
  966.   INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
  967. EXT char    no_usym[]
  968.   INIT("Can't use an undefined value as %s reference");
  969. EXT char    no_aelem[]
  970.   INIT("Modification of non-creatable array value attempted, subscript %d");
  971. EXT char    no_helem[]
  972.   INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
  973. EXT char    no_modify[]
  974.   INIT("Modification of a read-only value attempted");
  975. EXT char    no_mem[]
  976.   INIT("Out of memory!\n");
  977. EXT char    no_security[]
  978.   INIT("Insecure dependency in %s%s");
  979. EXT char    no_sock_func[]
  980.   INIT("Unsupported socket function \"%s\" called");
  981. EXT char    no_dir_func[]
  982.   INIT("Unsupported directory function \"%s\" called");
  983. EXT char    no_func[]
  984.   INIT("The %s function is unimplemented");
  985. EXT char    no_myglob[]
  986.   INIT("\"my\" variable %s can't be in a package");
  987.  
  988. EXT SV        sv_undef;
  989. EXT SV        sv_no;
  990. EXT SV        sv_yes;
  991. #ifdef CSH
  992.     EXT char *    cshname INIT(CSH);
  993.     EXT I32    cshlen;
  994. #endif
  995.  
  996. #ifdef DOINIT
  997. EXT char *sig_name[] = { SIG_NAME };
  998. EXT int   sig_num[]  = { SIG_NUM };
  999. #else
  1000. EXT char *sig_name[];
  1001. EXT int   sig_num[];
  1002. #endif
  1003.  
  1004. #ifdef DOINIT
  1005. EXT unsigned char fold[] = {    /* fast case folding table */
  1006.     0,    1,    2,    3,    4,    5,    6,    7,
  1007.     8,    9,    10,    11,    12,    13,    14,    15,
  1008.     16,    17,    18,    19,    20,    21,    22,    23,
  1009.     24,    25,    26,    27,    28,    29,    30,    31,
  1010.     32,    33,    34,    35,    36,    37,    38,    39,
  1011.     40,    41,    42,    43,    44,    45,    46,    47,
  1012.     48,    49,    50,    51,    52,    53,    54,    55,
  1013.     56,    57,    58,    59,    60,    61,    62,    63,
  1014.     64,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  1015.     'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
  1016.     'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
  1017.     'x',    'y',    'z',    91,    92,    93,    94,    95,
  1018.     96,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  1019.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  1020.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  1021.     'X',    'Y',    'Z',    123,    124,    125,    126,    127,
  1022.     128,    129,    130,    131,    132,    133,    134,    135,
  1023.     136,    137,    138,    139,    140,    141,    142,    143,
  1024.     144,    145,    146,    147,    148,    149,    150,    151,
  1025.     152,    153,    154,    155,    156,    157,    158,    159,
  1026.     160,    161,    162,    163,    164,    165,    166,    167,
  1027.     168,    169,    170,    171,    172,    173,    174,    175,
  1028.     176,    177,    178,    179,    180,    181,    182,    183,
  1029.     184,    185,    186,    187,    188,    189,    190,    191,
  1030.     192,    193,    194,    195,    196,    197,    198,    199,
  1031.     200,    201,    202,    203,    204,    205,    206,    207,
  1032.     208,    209,    210,    211,    212,    213,    214,    215,
  1033.     216,    217,    218,    219,    220,    221,    222,    223,    
  1034.     224,    225,    226,    227,    228,    229,    230,    231,
  1035.     232,    233,    234,    235,    236,    237,    238,    239,
  1036.     240,    241,    242,    243,    244,    245,    246,    247,
  1037.     248,    249,    250,    251,    252,    253,    254,    255
  1038. };
  1039. #else
  1040. EXT unsigned char fold[];
  1041. #endif
  1042.  
  1043. #ifdef DOINIT
  1044. EXT unsigned char freq[] = {    /* letter frequencies for mixed English/C */
  1045.     1,    2,    84,    151,    154,    155,    156,    157,
  1046.     165,    246,    250,    3,    158,    7,    18,    29,
  1047.     40,    51,    62,    73,    85,    96,    107,    118,
  1048.     129,    140,    147,    148,    149,    150,    152,    153,
  1049.     255,    182,    224,    205,    174,    176,    180,    217,
  1050.     233,    232,    236,    187,    235,    228,    234,    226,
  1051.     222,    219,    211,    195,    188,    193,    185,    184,
  1052.     191,    183,    201,    229,    181,    220,    194,    162,
  1053.     163,    208,    186,    202,    200,    218,    198,    179,
  1054.     178,    214,    166,    170,    207,    199,    209,    206,
  1055.     204,    160,    212,    216,    215,    192,    175,    173,
  1056.     243,    172,    161,    190,    203,    189,    164,    230,
  1057.     167,    248,    227,    244,    242,    255,    241,    231,
  1058.     240,    253,    169,    210,    245,    237,    249,    247,
  1059.     239,    168,    252,    251,    254,    238,    223,    221,
  1060.     213,    225,    177,    197,    171,    196,    159,    4,
  1061.     5,    6,    8,    9,    10,    11,    12,    13,
  1062.     14,    15,    16,    17,    19,    20,    21,    22,
  1063.     23,    24,    25,    26,    27,    28,    30,    31,
  1064.     32,    33,    34,    35,    36,    37,    38,    39,
  1065.     41,    42,    43,    44,    45,    46,    47,    48,
  1066.     49,    50,    52,    53,    54,    55,    56,    57,
  1067.     58,    59,    60,    61,    63,    64,    65,    66,
  1068.     67,    68,    69,    70,    71,    72,    74,    75,
  1069.     76,    77,    78,    79,    80,    81,    82,    83,
  1070.     86,    87,    88,    89,    90,    91,    92,    93,
  1071.     94,    95,    97,    98,    99,    100,    101,    102,
  1072.     103,    104,    105,    106,    108,    109,    110,    111,
  1073.     112,    113,    114,    115,    116,    117,    119,    120,
  1074.     121,    122,    123,    124,    125,    126,    127,    128,
  1075.     130,    131,    132,    133,    134,    135,    136,    137,
  1076.     138,    139,    141,    142,    143,    144,    145,    146
  1077. };
  1078. #else
  1079. EXT unsigned char freq[];
  1080. #endif
  1081.  
  1082. #ifdef DEBUGGING
  1083. #ifdef DOINIT
  1084. EXT char* block_type[] = {
  1085.     "NULL",
  1086.     "SUB",
  1087.     "EVAL",
  1088.     "LOOP",
  1089.     "SUBST",
  1090.     "BLOCK",
  1091. };
  1092. #else
  1093. EXT char* block_type[];
  1094. #endif
  1095. #endif
  1096.  
  1097. /*****************************************************************************/
  1098. /* This lexer/parser stuff is currently global since yacc is hard to reenter */
  1099. /*****************************************************************************/
  1100. /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
  1101.  
  1102. #include "perly.h"
  1103.  
  1104. typedef enum {
  1105.     XOPERATOR,
  1106.     XTERM,
  1107.     XREF,
  1108.     XSTATE,
  1109.     XBLOCK,
  1110.     XTERMBLOCK
  1111. } expectation;
  1112.  
  1113. EXT U32        lex_state;    /* next token is determined */
  1114. EXT U32        lex_defer;    /* state after determined token */
  1115. EXT expectation    lex_expect;    /* expect after determined token */
  1116. EXT I32        lex_brackets;    /* bracket count */
  1117. EXT I32        lex_formbrack;    /* bracket count at outer format level */
  1118. EXT I32        lex_fakebrack;    /* outer bracket is mere delimiter */
  1119. EXT I32        lex_casemods;    /* casemod count */
  1120. EXT I32        lex_dojoin;    /* doing an array interpolation */
  1121. EXT I32        lex_starts;    /* how many interps done on level */
  1122. EXT SV *    lex_stuff;    /* runtime pattern from m// or s/// */
  1123. EXT SV *    lex_repl;    /* runtime replacement from s/// */
  1124. EXT OP *    lex_op;        /* extra info to pass back on op */
  1125. EXT OP *    lex_inpat;    /* in pattern $) and $| are special */
  1126. EXT I32        lex_inwhat;    /* what kind of quoting are we in */
  1127. EXT char *    lex_brackstack;    /* what kind of brackets to pop */
  1128. EXT char *    lex_casestack;    /* what kind of case mods in effect */
  1129.  
  1130. /* What we know when we're in LEX_KNOWNEXT state. */
  1131. EXT YYSTYPE    nextval[5];    /* value of next token, if any */
  1132. EXT I32        nexttype[5];    /* type of next token */
  1133. EXT I32        nexttoke;
  1134.  
  1135. EXT FILE * VOL    rsfp INIT(Nullfp);
  1136. EXT SV *    linestr;
  1137. EXT char *    bufptr;
  1138. EXT char *    oldbufptr;
  1139. EXT char *    oldoldbufptr;
  1140. EXT char *    bufend;
  1141. EXT expectation expect INIT(XSTATE);    /* how to interpret ambiguous tokens */
  1142. EXT AV *     rsfp_filters;
  1143.  
  1144. EXT I32        multi_start;    /* 1st line of multi-line string */
  1145. EXT I32        multi_end;    /* last line of multi-line string */
  1146. EXT I32        multi_open;    /* delimiter of said string */
  1147. EXT I32        multi_close;    /* delimiter of said string */
  1148.  
  1149. EXT GV *    scrgv;
  1150. EXT I32        error_count;    /* how many errors so far, max 10 */
  1151. EXT I32        subline;    /* line this subroutine began on */
  1152. EXT SV *    subname;    /* name of current subroutine */
  1153.  
  1154. EXT CV *    compcv;        /* currently compiling subroutine */
  1155. EXT AV *    comppad;    /* storage for lexically scoped temporaries */
  1156. EXT AV *    comppad_name;    /* variable names for "my" variables */
  1157. EXT I32        comppad_name_fill;/* last "introduced" variable offset */
  1158. EXT I32        min_intro_pending;/* start of vars to introduce */
  1159. EXT I32        max_intro_pending;/* end of vars to introduce */
  1160. EXT I32        padix;        /* max used index in current "register" pad */
  1161. EXT I32        padix_floor;    /* how low may inner block reset padix */
  1162. EXT I32        pad_reset_pending; /* reset pad on next attempted alloc */
  1163. EXT COP        compiling;
  1164.  
  1165. EXT I32        thisexpr;    /* name id for nothing_in_common() */
  1166. EXT char *    last_uni;    /* position of last named-unary operator */
  1167. EXT char *    last_lop;    /* position of last list operator */
  1168. EXT OPCODE    last_lop_op;    /* last list operator */
  1169. EXT bool    in_my;        /* we're compiling a "my" declaration */
  1170. #ifdef FCRYPT
  1171. EXT I32        cryptseen;    /* has fast crypt() been initialized? */
  1172. #endif
  1173.  
  1174. EXT U32        hints;        /* various compilation flags */
  1175.  
  1176.                 /* Note: the lowest 8 bits are reserved for
  1177.                    stuffing into op->op_private */
  1178. #define HINT_INTEGER        0x00000001
  1179. #define HINT_STRICT_REFS    0x00000002
  1180.  
  1181. #define HINT_BLOCK_SCOPE    0x00000100
  1182. #define HINT_STRICT_SUBS    0x00000200
  1183. #define HINT_STRICT_VARS    0x00000400
  1184.  
  1185. /**************************************************************************/
  1186. /* This regexp stuff is global since it always happens within 1 expr eval */
  1187. /**************************************************************************/
  1188.  
  1189. EXT char *    regprecomp;    /* uncompiled string. */
  1190. EXT char *    regparse;    /* Input-scan pointer. */
  1191. EXT char *    regxend;    /* End of input for compile */
  1192. EXT I32        regnpar;    /* () count. */
  1193. EXT char *    regcode;    /* Code-emit pointer; ®dummy = don't. */
  1194. EXT I32        regsize;    /* Code size. */
  1195. EXT I32        regnaughty;    /* How bad is this pattern? */
  1196. EXT I32        regsawback;    /* Did we see \1, ...? */
  1197.  
  1198. EXT char *    reginput;    /* String-input pointer. */
  1199. EXT char *    regbol;        /* Beginning of input, for ^ check. */
  1200. EXT char *    regeol;        /* End of input, for $ check. */
  1201. EXT char **    regstartp;    /* Pointer to startp array. */
  1202. EXT char **    regendp;    /* Ditto for endp. */
  1203. EXT U32 *    reglastparen;    /* Similarly for lastparen. */
  1204. EXT char *    regtill;    /* How far we are required to go. */
  1205. EXT U16        regflags;    /* are we folding, multilining? */
  1206. EXT char    regprev;    /* char before regbol, \n if none */
  1207.  
  1208. /***********************************************/
  1209. /* Global only to current interpreter instance */
  1210. /***********************************************/
  1211.  
  1212. #ifdef MULTIPLICITY
  1213. #define IEXT
  1214. #define IINIT(x)
  1215. struct interpreter {
  1216. #else
  1217. #define IEXT EXT
  1218. #define IINIT(x) INIT(x)
  1219. #endif
  1220.  
  1221. /* pseudo environmental stuff */
  1222. IEXT int    Iorigargc;
  1223. IEXT char **    Iorigargv;
  1224. IEXT GV *    Ienvgv;
  1225. IEXT GV *    Isiggv;
  1226. IEXT GV *    Iincgv;
  1227. IEXT char *    Iorigfilename;
  1228. IEXT SV *    Idiehook;
  1229. IEXT SV *    Iwarnhook;
  1230. IEXT SV *    Iparsehook;
  1231.  
  1232. /* Various states of an input record separator SV (rs, nrs) */
  1233. #define RsSNARF(sv)   (! SvOK(sv))
  1234. #define RsSIMPLE(sv)  (SvOK(sv) && SvCUR(sv))
  1235. #define RsPARA(sv)    (SvOK(sv) && ! SvCUR(sv))
  1236.  
  1237. /* switches */
  1238. IEXT char *    Icddir;
  1239. IEXT bool    Iminus_c;
  1240. IEXT char    Ipatchlevel[10];
  1241. IEXT char **    Ilocalpatches;
  1242. IEXT SV *    Inrs;
  1243. IEXT char *    Isplitstr IINIT(" ");
  1244. IEXT bool    Ipreprocess;
  1245. IEXT bool    Iminus_n;
  1246. IEXT bool    Iminus_p;
  1247. IEXT bool    Iminus_l;
  1248. IEXT bool    Iminus_a;
  1249. IEXT bool    Iminus_F;
  1250. IEXT bool    Idoswitches;
  1251. IEXT bool    Idowarn;
  1252. IEXT bool    Idoextract;
  1253. IEXT bool    Isawampersand;    /* must save all match strings */
  1254. IEXT bool    Isawstudy;    /* do fbm_instr on all strings */
  1255. IEXT bool    Isawi;        /* study must assume case insensitive */
  1256. IEXT bool    Isawvec;
  1257. IEXT bool    Iunsafe;
  1258. IEXT bool    Ido_undump;        /* -u or dump seen? */
  1259. IEXT char *    Iinplace;
  1260. IEXT char *    Ie_tmpname;
  1261. IEXT FILE *    Ie_fp;
  1262. IEXT VOL U32    Idebug;
  1263. IEXT U32    Iperldb;
  1264.     /* This value may be raised by extensions for testing purposes */
  1265. IEXT int    Iperl_destruct_level;    /* 0=none, 1=full, 2=full with checks */
  1266.  
  1267. /* magical thingies */
  1268. IEXT Time_t    Ibasetime;        /* $^T */
  1269. IEXT SV *    Iformfeed;        /* $^L */
  1270. IEXT char *    Ichopset IINIT(" \n-");    /* $: */
  1271. IEXT SV *    Irs;            /* $/ */
  1272. IEXT char *    Iofs;            /* $, */
  1273. IEXT STRLEN    Iofslen;
  1274. IEXT char *    Iors;            /* $\ */
  1275. IEXT STRLEN    Iorslen;
  1276. IEXT char *    Iofmt;            /* $# */
  1277. IEXT I32    Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */
  1278. IEXT int    Imultiline;      /* $*--do strings hold >1 line? */
  1279. IEXT U32    Istatusvalue;    /* $? */
  1280.  
  1281. IEXT struct stat Istatcache;        /* _ */
  1282. IEXT GV *    Istatgv;
  1283. IEXT SV *    Istatname IINIT(Nullsv);
  1284.  
  1285. /* shortcuts to various I/O objects */
  1286. IEXT GV *    Istdingv;
  1287. IEXT GV *    Ilast_in_gv;
  1288. IEXT GV *    Idefgv;
  1289. IEXT GV *    Iargvgv;
  1290. IEXT GV *    Idefoutgv;
  1291. IEXT GV *    Iargvoutgv;
  1292.  
  1293. /* shortcuts to regexp stuff */
  1294. IEXT GV *    Ileftgv;
  1295. IEXT GV *    Iampergv;
  1296. IEXT GV *    Irightgv;
  1297. IEXT PMOP *    Icurpm;        /* what to do \ interps from */
  1298. IEXT I32 *    Iscreamfirst;
  1299. IEXT I32 *    Iscreamnext;
  1300. IEXT I32    Imaxscream IINIT(-1);
  1301. IEXT SV *    Ilastscream;
  1302.  
  1303. /* shortcuts to misc objects */
  1304. IEXT GV *    Ierrgv;
  1305.  
  1306. /* shortcuts to debugging objects */
  1307. IEXT GV *    IDBgv;
  1308. IEXT GV *    IDBline;
  1309. IEXT GV *    IDBsub;
  1310. IEXT SV *    IDBsingle;
  1311. IEXT SV *    IDBtrace;
  1312. IEXT SV *    IDBsignal;
  1313. IEXT AV *    Ilineary;    /* lines of script for debugger */
  1314. IEXT AV *    Idbargs;    /* args to call listed by caller function */
  1315.  
  1316. /* symbol tables */
  1317. IEXT HV *    Idefstash;    /* main symbol table */
  1318. IEXT HV *    Icurstash;    /* symbol table for current package */
  1319. IEXT HV *    Idebstash;    /* symbol table for perldb package */
  1320. IEXT SV *    Icurstname;    /* name of current package */
  1321. IEXT AV *    Ibeginav;    /* names of BEGIN subroutines */
  1322. IEXT AV *    Iendav;        /* names of END subroutines */
  1323. IEXT AV *    Ipad;        /* storage for lexically scoped temporaries */
  1324. IEXT AV *    Ipadname;    /* variable names for "my" variables */
  1325.  
  1326. /* memory management */
  1327. IEXT SV **    Itmps_stack;
  1328. IEXT I32    Itmps_ix IINIT(-1);
  1329. IEXT I32    Itmps_floor IINIT(-1);
  1330. IEXT I32    Itmps_max;
  1331. IEXT I32    Isv_count;    /* how many SV* are currently allocated */
  1332. IEXT I32    Isv_objcount;    /* how many objects are currently allocated */
  1333. IEXT SV*    Isv_root;    /* storage for SVs belonging to interp */
  1334. IEXT SV*    Isv_arenaroot;    /* list of areas for garbage collection */
  1335.  
  1336. /* funky return mechanisms */
  1337. IEXT I32    Ilastspbase;
  1338. IEXT I32    Ilastsize;
  1339. IEXT int    Iforkprocess;    /* so do_open |- can return proc# */
  1340.  
  1341. /* subprocess state */
  1342. IEXT AV *    Ifdpid;        /* keep fd-to-pid mappings for my_popen */
  1343. IEXT HV *    Ipidstatus;    /* keep pid-to-status mappings for waitpid */
  1344.  
  1345. /* internal state */
  1346. IEXT VOL int    Iin_eval;    /* trap "fatal" errors? */
  1347. IEXT OP *    Irestartop;    /* Are we propagating an error from croak? */
  1348. IEXT int    Idelaymagic;    /* ($<,$>) = ... */
  1349. IEXT bool    Idirty;        /* In the middle of tearing things down? */
  1350. IEXT U8        Ilocalizing;    /* are we processing a local() list? */
  1351. IEXT bool    Itainted;    /* using variables controlled by $< */
  1352. IEXT bool    Itainting;    /* doing taint checks */
  1353. IEXT char *    Iop_mask IINIT(NULL);    /* masked operations for safe evals */
  1354.  
  1355. /* trace state */
  1356. IEXT I32    Idlevel;
  1357. IEXT I32    Idlmax IINIT(128);
  1358. IEXT char *    Idebname;
  1359. IEXT char *    Idebdelim;
  1360.  
  1361. /* current interpreter roots */
  1362. IEXT CV *    Imain_cv;
  1363. IEXT OP *    Imain_root;
  1364. IEXT OP *    Imain_start;
  1365. IEXT OP *    Ieval_root;
  1366. IEXT OP *    Ieval_start;
  1367.  
  1368. /* runtime control stuff */
  1369. IEXT COP * VOL    Icurcop IINIT(&compiling);
  1370. IEXT line_t    Icopline IINIT(NOLINE);
  1371. IEXT CONTEXT *    Icxstack;
  1372. IEXT I32    Icxstack_ix IINIT(-1);
  1373. IEXT I32    Icxstack_max IINIT(128);
  1374. IEXT Sigjmp_buf    Itop_env;
  1375. IEXT I32    Irunlevel;
  1376.  
  1377. /* stack stuff */
  1378. IEXT AV *    Istack;        /* THE STACK */
  1379. IEXT AV *    Imainstack;    /* the stack when nothing funny is happening */
  1380. IEXT SV **    Imystack_base;    /* stack->array_ary */
  1381. IEXT SV **    Imystack_sp;    /* stack pointer now */
  1382. IEXT SV **    Imystack_max;    /* stack->array_ary + stack->array_max */
  1383.  
  1384. /* format accumulators */
  1385. IEXT SV *    Iformtarget;
  1386. IEXT SV *    Ibodytarget;
  1387. IEXT SV *    Itoptarget;
  1388.  
  1389. /* statics moved here for shared library purposes */
  1390. IEXT SV        Istrchop;    /* return value from chop */
  1391. IEXT int    Ifilemode;    /* so nextargv() can preserve mode */
  1392. IEXT int    Ilastfd;    /* what to preserve mode on */
  1393. IEXT char *    Ioldname;    /* what to preserve mode on */
  1394. IEXT char **    IArgv;        /* stuff to free from do_aexec, vfork safe */
  1395. IEXT char *    ICmd;        /* stuff to free from do_aexec, vfork safe */
  1396. IEXT OP *    Isortcop;    /* user defined sort routine */
  1397. IEXT HV *    Isortstash;    /* which is in some package or other */
  1398. IEXT GV *    Ifirstgv;    /* $a */
  1399. IEXT GV *    Isecondgv;    /* $b */
  1400. IEXT AV *    Isortstack;    /* temp stack during pp_sort() */
  1401. IEXT AV *    Isignalstack;    /* temp stack during sighandler() */
  1402. IEXT SV *    Imystrk;    /* temp key string for do_each() */
  1403. IEXT I32    Idumplvl;    /* indentation level on syntax tree dump */
  1404. IEXT PMOP *    Ioldlastpm;    /* for saving regexp context during debugger */
  1405. IEXT I32    Igensym;    /* next symbol for getsym() to define */
  1406. IEXT bool    Ipreambled;
  1407. IEXT AV *    Ipreambleav;
  1408. IEXT int    Ilaststatval IINIT(-1);
  1409. IEXT I32    Ilaststype IINIT(OP_STAT);
  1410.  
  1411. #undef IEXT
  1412. #undef IINIT
  1413.  
  1414. #ifdef MULTIPLICITY
  1415. };
  1416. #else
  1417. struct interpreter {
  1418.     char broiled;
  1419. };
  1420. #endif
  1421.  
  1422. #include "pp.h"
  1423.  
  1424. #ifdef __cplusplus
  1425. extern "C" {
  1426. #endif
  1427.  
  1428. #ifdef __cplusplus
  1429. #  ifndef I_STDARG
  1430. #    define I_STDARG 1
  1431. #  endif
  1432. #endif
  1433.  
  1434. #ifdef I_STDARG
  1435. #  include <stdarg.h>
  1436. #else
  1437. #  ifdef I_VARARGS
  1438. #    include <varargs.h>
  1439. #  endif
  1440. #endif
  1441.  
  1442. #include "proto.h"
  1443.  
  1444. #ifdef EMBED
  1445. #define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
  1446. #define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
  1447. #else
  1448. #define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
  1449. #define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
  1450. #endif
  1451.  
  1452. #ifdef __cplusplus
  1453. }
  1454. #endif
  1455.  
  1456. /* The following must follow proto.h */
  1457.  
  1458. #ifdef DOINIT
  1459. EXT MGVTBL vtbl_sv =    {magic_get,
  1460.                 magic_set,
  1461.                     magic_len,
  1462.                         0,    0};
  1463. EXT MGVTBL vtbl_env =    {0,    0,    0,    0,    0};
  1464. EXT MGVTBL vtbl_envelem =    {0,    magic_setenv,
  1465.                     0,    magic_clearenv,
  1466.                             0};
  1467. EXT MGVTBL vtbl_sig =    {0,    0,         0, 0, 0};
  1468. EXT MGVTBL vtbl_sigelem =    {0,    magic_setsig,
  1469.                     0,    0,    0};
  1470. EXT MGVTBL vtbl_pack =    {0,    0,    0,    magic_wipepack,
  1471.                             0};
  1472. EXT MGVTBL vtbl_packelem =    {magic_getpack,
  1473.                 magic_setpack,
  1474.                     0,    magic_clearpack,
  1475.                             0};
  1476. EXT MGVTBL vtbl_dbline =    {0,    magic_setdbline,
  1477.                     0,    0,    0};
  1478. EXT MGVTBL vtbl_isa =    {0,    magic_setisa,
  1479.                     0,    0,    0};
  1480. EXT MGVTBL vtbl_isaelem =    {0,    magic_setisa,
  1481.                     0,    0,    0};
  1482. EXT MGVTBL vtbl_arylen =    {magic_getarylen,
  1483.                 magic_setarylen,
  1484.                     0,    0,    0};
  1485. EXT MGVTBL vtbl_glob =    {magic_getglob,
  1486.                 magic_setglob,
  1487.                     0,    0,    0};
  1488. EXT MGVTBL vtbl_mglob =    {0,    magic_setmglob,
  1489.                     0,    0,    0};
  1490. EXT MGVTBL vtbl_taint =    {magic_gettaint,magic_settaint,
  1491.                     0,    0,    0};
  1492. EXT MGVTBL vtbl_substr =    {0,    magic_setsubstr,
  1493.                     0,    0,    0};
  1494. EXT MGVTBL vtbl_vec =    {0,    magic_setvec,
  1495.                     0,    0,    0};
  1496. EXT MGVTBL vtbl_pos =    {magic_getpos,
  1497.                 magic_setpos,
  1498.                     0,    0,    0};
  1499. EXT MGVTBL vtbl_bm =    {0,    magic_setbm,
  1500.                     0,    0,    0};
  1501. EXT MGVTBL vtbl_uvar =    {magic_getuvar,
  1502.                 magic_setuvar,
  1503.                     0,    0,    0};
  1504.  
  1505. #ifdef OVERLOAD
  1506. EXT MGVTBL vtbl_amagic =       {0,     magic_setamagic,
  1507.                                         0,      0,      magic_setamagic};
  1508. EXT MGVTBL vtbl_amagicelem =   {0,     magic_setamagic,
  1509.                                         0,      0,      magic_setamagic};
  1510. #endif /* OVERLOAD */
  1511.  
  1512. #else
  1513. EXT MGVTBL vtbl_sv;
  1514. EXT MGVTBL vtbl_env;
  1515. EXT MGVTBL vtbl_envelem;
  1516. EXT MGVTBL vtbl_sig;
  1517. EXT MGVTBL vtbl_sigelem;
  1518. EXT MGVTBL vtbl_pack;
  1519. EXT MGVTBL vtbl_packelem;
  1520. EXT MGVTBL vtbl_dbline;
  1521. EXT MGVTBL vtbl_isa;
  1522. EXT MGVTBL vtbl_isaelem;
  1523. EXT MGVTBL vtbl_arylen;
  1524. EXT MGVTBL vtbl_glob;
  1525. EXT MGVTBL vtbl_mglob;
  1526. EXT MGVTBL vtbl_taint;
  1527. EXT MGVTBL vtbl_substr;
  1528. EXT MGVTBL vtbl_vec;
  1529. EXT MGVTBL vtbl_pos;
  1530. EXT MGVTBL vtbl_bm;
  1531. EXT MGVTBL vtbl_uvar;
  1532.  
  1533. #ifdef OVERLOAD
  1534. EXT MGVTBL vtbl_amagic;
  1535. EXT MGVTBL vtbl_amagicelem;
  1536. #endif /* OVERLOAD */
  1537.  
  1538. #endif
  1539.  
  1540. #ifdef OVERLOAD
  1541. EXT long amagic_generation;
  1542.  
  1543. #define NofAMmeth 29
  1544. #ifdef DOINIT
  1545. EXT char * AMG_names[NofAMmeth][2] = {
  1546.   {"fallback","abs"},
  1547.   {"bool", "nomethod"},
  1548.   {"\"\"", "0+"},
  1549.   {"+","+="},
  1550.   {"-","-="},
  1551.   {"*", "*="},
  1552.   {"/", "/="},
  1553.   {"%", "%="},
  1554.   {"**", "**="},
  1555.   {"<<", "<<="},
  1556.   {">>", ">>="},
  1557.   {"&", "&="},
  1558.   {"|", "|="},
  1559.   {"^", "^="},
  1560.   {"<", "<="},
  1561.   {">", ">="},
  1562.   {"==", "!="},
  1563.   {"<=>", "cmp"},
  1564.   {"lt", "le"},
  1565.   {"gt", "ge"},
  1566.   {"eq", "ne"},
  1567.   {"!", "~"},
  1568.   {"++", "--"},
  1569.   {"atan2", "cos"},
  1570.   {"sin", "exp"},
  1571.   {"log", "sqrt"},
  1572.   {"x","x="},
  1573.   {".",".="},
  1574.   {"=","neg"}
  1575. };
  1576. #else
  1577. EXT char * AMG_names[NofAMmeth][2];
  1578. #endif /* def INITAMAGIC */
  1579.  
  1580. struct  am_table        {
  1581.   long was_ok_sub;
  1582.   long was_ok_am;
  1583.   CV* table[NofAMmeth*2];
  1584.   long fallback;
  1585. };
  1586. typedef struct am_table AMT;
  1587.  
  1588. #define AMGfallNEVER    1
  1589. #define AMGfallNO    2
  1590. #define AMGfallYES    3
  1591.  
  1592. enum {
  1593.   fallback_amg,    abs_amg,
  1594.   bool__amg,    nomethod_amg,
  1595.   string_amg,    numer_amg,
  1596.   add_amg,    add_ass_amg,
  1597.   subtr_amg,    subtr_ass_amg,
  1598.   mult_amg,    mult_ass_amg,
  1599.   div_amg,    div_ass_amg,
  1600.   mod_amg,    mod_ass_amg,
  1601.   pow_amg,    pow_ass_amg,
  1602.   lshift_amg,    lshift_ass_amg,
  1603.   rshift_amg,    rshift_ass_amg,
  1604.   band_amg,    band_ass_amg,
  1605.   bor_amg,    bor_ass_amg,
  1606.   bxor_amg,    bxor_ass_amg,
  1607.   lt_amg,    le_amg,
  1608.   gt_amg,    ge_amg,
  1609.   eq_amg,    ne_amg,
  1610.   ncmp_amg,    scmp_amg,
  1611.   slt_amg,    sle_amg,
  1612.   sgt_amg,    sge_amg,
  1613.   seq_amg,    sne_amg,
  1614.   not_amg,    compl_amg,
  1615.   inc_amg,    dec_amg,
  1616.   atan2_amg,    cos_amg,
  1617.   sin_amg,    exp_amg,
  1618.   log_amg,    sqrt_amg,
  1619.   repeat_amg,   repeat_ass_amg,
  1620.   concat_amg,    concat_ass_amg,
  1621.   copy_amg,    neg_amg
  1622. };
  1623. #endif /* OVERLOAD */
  1624.  
  1625. #endif /* Include guard */
  1626.